package com.zsy.service.impl;

import com.zsy.entity.TalentRecruitment;
import com.zsy.entity.UserResumeCenter;
import com.zsy.mapper.IShareMapper;
import com.zsy.service.IShareService;
import com.zsy.utils.Result;
//import com.zsy.utils.ThreadLocalUtil;
import com.zsy.vo.NewJobVO;
import com.zsy.vo.business;
import com.zsy.vo.position;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ShareServiceImpl implements IShareService {
@Autowired
    private IShareMapper smr;

    @Override
    public Result Selectsome() {

//        Map<String,Object> mp = ThreadLocalUtil.get();
//        String department = (String) mp.get("department");

//        if(department.equals("人事部") || department.equals("研发部") || department.equals("管理员")){
            List<NewJobVO> newJobVOS = smr.countResumesByPosition();
            for (int i   = 0; i < newJobVOS.size(); i++) {
                smr.uprr(newJobVOS.get(i).getPositionName(),newJobVOS.get(i).getResumeCount());
            }
        return Result.ok(smr.getsomeInformation());

//        }
//        else {
//            return Result.error("错误");
//        }
    }

    @Override
    public Result Rendering() {


//        Map<String,Object> mp = ThreadLocalUtil.get();
//        String department = (String) mp.get("department");

//        if(department.equals("人事部") || department.equals("研发部") || department.equals("管理员")){
            List<NewJobVO> newJobVOS = smr.countResumesByPosition();
            for (int i   = 0; i < newJobVOS.size(); i++) {
                smr.uprr(newJobVOS.get(i).getPositionName(),newJobVOS.get(i).getResumeCount());
            }
        System.out.println(smr.getAllInformation());
            return Result.ok(smr.getAllInformation());
//        }
//        else {
//            return Result.error("错误");
//        }

    }

    @Override
    public Result AddResume(TalentRecruitment t) {
        if (t.getPositionName() == null || t.getPositionName().isEmpty()) {
            return Result.error("职位名称未填写");
        }
        // 检查所属机构是否为空或只包含空格
        if (t.getDepartment() == null || t.getDepartment().isEmpty()) {
            return Result.error("所属机构未填写");
        }
        // 检查缺少人数是否为空
        if (t.getShortageOfPopulation() == null) {
            return Result.error("缺少人数未填写");
        }
        // 检查添加人是否为空或只包含空格
        if (t.getAddPeople() == null || t.getAddPeople().isEmpty()) {
            return Result.error("添加人未填写");
        }
        // 假设smr是您的服务或DAO对象，AddInformation是添加信息的方法
        Integer integer = smr.AddInformation(t);
        // 根据添加结果返回成功或失败的消息
        return Result.ok(integer == 1 ? "添加成功" : "添加失败");
    }

    @Override
    public Result UpdataResume(TalentRecruitment t) {
        if (t.getTalentId()==null)
            return Result.error("请选择修改数据");
        if (t.getShortageOfPopulation()==null)
            return Result.error("缺少人数未填写");
        if (t.getModifier()==null || t.getModifier()=="")
            return Result.error("修改人未填写");
        if (t.getShortageOfPopulation()<0){
            return Result.error("缺少人数填写错误");
        }
        Integer integer = smr.UpdataInfomation(t);
        if (integer == 1){
            return Result.ok("修改成功");
        }else {
            return Result.error("修改失败");
        }
    }

    @Override
    public Result DeleteResume(Integer[] talentId, String deleterPeople) {
        if (talentId==null)
            return Result.error("请选择删除信息");
        if (deleterPeople==null||deleterPeople=="")
            return Result.error("未发现删除人");
        if (smr.DeleteInfomation(talentId,deleterPeople)==1)
            return Result.ok("删除成功");
        return Result.error("删除失败");
    }


    @Override
    public Result AddResume(UserResumeCenter UR) {
        if (UR.getName()==null||UR.getName()=="")
            return Result.error("姓名未填写");
        if (UR.getSex()==null || UR.getSex()=="")
            return Result.error("性别未填写");
        if (UR.getPhone()==null || UR.getPhone()=="")
            return Result.error("手机号为空");
        if (UR.getPositionName()==null || UR.getPositionName()=="")
            return Result.error("岗位为空");
        if (UR.getIdcard()==null || UR.getIdcard()=="")
            return Result.error("身份证为空");
        if (UR.getSource()==null || UR.getSource()=="")
            return Result.error("来源渠道为空");
        if (UR.getClassify()==null || UR.getClassify()=="")
            return Result.error("简历分类为空");
        if (UR.getWorkExperience()==null || UR.getWorkExperience()=="")
            return Result.error("工作经验为空");
        Integer integer = smr.AddResume(UR);
        if (integer==1){
            return Result.ok("添加成功");
        }else {
            return Result.error("添加失败");
        }
    }

    @Override
    public Result Updatepersonnel(Integer id, String personnelName) {
        if (id==null)
            return Result.error("请选择删除数据");
        if (personnelName==null || personnelName=="")
            return Result.error("面试人没查到");
        Integer updatepersonnel = smr.Updatepersonnel(id,personnelName);
        if (updatepersonnel==1){
            List<position> positions = smr.countPersonnelByPositionName();
            for (int i = 0; i < positions.size(); i++) {
                smr.upp(positions.get(i).getPositionName(),positions.get(i).getPersonnelCount());
            }
            return Result.ok("预约成功");
        }else {
            return Result.error("预约失败");
        }
    }

    @Override
    public Result Updatetechnical(Integer id, String technicalName) {
        if (id==null)
            return Result.error("请选择面试数据");
        if (technicalName==null || technicalName=="")
            return Result.error("面试官没查到");
        Integer updatetechnical = smr.Updatetechnical(id, technicalName);
        if (updatetechnical==1){
            List<business> business = smr.business();
            for (int i = 0; i < business.size(); i++) {
                smr.upbus(business.get(i).getPositionName(),business.get(i).getBusinessReviewCount());
            }
            return Result.ok("预约成功");
        }else {
            return Result.error("预约失败");
        }
    }

    @Override
    public Result interview(Integer id, String admissionName, Integer admission) {
        if (id==null)
            return Result.error("请选择面试信息");
        if (admissionName==null || admissionName=="")
            return Result.error("未查到操作用户");
        if (admission==null)
            return Result.error("请选择录取状态");
        Integer interview = smr.interview(id, admissionName, admission);
        if (interview==1){
            if (admission==1)
                return Result.ok("录取成功");
            if (admission==2)
                return Result.error("录取失败");
        }
        return Result.error("操作失败");
    }

    @Override
    public Result seleURS() {
        return Result.ok(smr.seleURC());
    }

    @Override
    public Result selesomeURS() {
        return Result.ok(smr.selesomeURC());
    }

}
